package com.example.demo.entity;

import java.util.Collection;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * 用户结构
 * @author Yuri
 *
 */

//@Entity 表示该类为实体类，实体类会映射成一张表
@Entity
//@Table 制定映射的表名
@Table(name = "T_User")
public class User implements UserDetails {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	// 设置为主键
	@Id
	// 设置主键的增长方式
	@GeneratedValue
	private Long id;
	private String userName;     	// 用户名
	private String userPw;			// 登录密码
	private Boolean isAvailable;	// 是否可用
	@ManyToMany(cascade = {CascadeType.REFRESH},fetch = FetchType.EAGER)
	private List<Role> role;			// 对应的角色
	@OneToOne
	private Depa depa;				// 对应的部门
	
	//   get和set方法
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getUserPw() {
		return userPw;
	}
	public void setUserPw(String userPw) {
		this.userPw = userPw;
	}
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public List<Role> getRole() {
		return role;
	}
	public void setRole(List<Role> role) {
		this.role = role;
	}
	public Boolean getIsAvailable() {
		return isAvailable;
	}
	public void setIsAvailable(Boolean isAvailable) {
		this.isAvailable = isAvailable;
	}
	public Depa getDepa() {
		return depa;
	}
	public void setDepa(Depa depa) {
		this.depa = depa;
	}
	//  get和set方法结束
	// toString方法
	@Override
	public String toString() {
		return "User [id=" + id + ", userName=" + userName + ", userPw=" + userPw + ", isAvailable=" + isAvailable
				+ ", role=" + role + ", depa=" + depa + "]";
	}
	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {
		return null;
	}
	@Override
	public String getPassword() {
		// TODO Auto-generated method stub
		return this.userPw;
	}
	@Override
	public String getUsername() {
		// TODO Auto-generated method stub
		return this.userName;
	}
	@Override
	public boolean isAccountNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean isAccountNonLocked() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean isCredentialsNonExpired() {
		// TODO Auto-generated method stub
		return true;
	}
	@Override
	public boolean isEnabled() {
		// TODO Auto-generated method stub
		return true;
	}
	
}
